import * as apis from '@/apis/modules/setPassword.js';

const setPassword = {
	namespaced: true,
	state: {
		hasSetPayPassword: false
	},
	mutations: {
		save(state, {field, payload}) {
		  if (Object.prototype.toString.call(payload) === '[object Object]') {
			state[field] = { ...state[field], ...payload }
		  } else {
			state[field] = payload
		  }
		}
	},
	actions: {
		getVerCode({commit}, phoneNo) {
			return apis.getVerCode(phoneNo)
		},
		
		verify({commit}, payload) {
			return apis.verify(payload)
		},
		
		getPasswordStatus({ commit }) {
			apis.getPasswordStatus()
				.then(({data}) => {
					commit('save', {field: 'hasSetPayPassword', payload: data})
				})
		},

		checkOriginalPassword({ commit }, oldPaymentpassword) {
			return apis.checkOriginalPassword()
		},

		setPassword({ commit }, payload) {
			return apis.setPassword(payload)
		}
	}
}

export default setPassword